LCORE-628: Elementary OpenAPI integration tests#481
LCORE-628: Elementary OpenAPI integration tests#481tisnik merged 1 commit intolightspeed-core:mainfrom
Conversation
WalkthroughAdds a new integration test module that loads Changes
Sequence Diagram(s)Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
c4b5e9a to
827524d
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (8)
tests/integration/test_openapi_json.py (8)
1-6: Add a module docstring to satisfy linter C0114 and describe intent.+"""Integration tests validating docs/openapi.json structure and key endpoints.""" + import json from pathlib import Path import typing as t import pytest
7-13: Strategy comment mentions components checks, but no tests cover them. Consider adding a minimal schema presence test.@@ # * presence and key attributes of important component schemas (enums, required fields) @@ OPENAPI_FILE = "docs/openapi.json" + +def test_components_schemas_present(spec: dict): + """Ensure components/schemas section exists and is non-empty.""" + components = spec.get("components") or {} + schemas = components.get("schemas") or {} + assert isinstance(schemas, dict) and schemas, "components.schemas must be a non-empty object" +
17-25: Remove R1710 (inconsistent return) and provide clearer failures, including JSON decode errors.def _load_openapi_spec() -> dict: """Load OpenAPI specification from configured path.""" path = Path(OPENAPI_FILE) - if path.is_file(): - with path.open("r", encoding="utf-8") as f: - return json.load(f) - - pytest.fail("OpenAPI spec not found") + if not path.is_file(): + pytest.fail(f"OpenAPI spec not found at {path}") + try: + with path.open("r", encoding="utf-8") as f: + return json.load(f) + except json.JSONDecodeError as e: + pytest.fail(f"Invalid JSON in OpenAPI spec at {path}: {e}")
27-31: Rename fixture ‘spec’ to ‘openapi_spec’ to silence redefined-outer-name warnings and improve clarity; update callsites.@pytest.fixture(scope="module") -def spec() -> dict: +def openapi_spec() -> dict: """Fixture containing OpenAPI specification represented as a dictionary.""" return _load_openapi_spec() @@ -def test_openapi_top_level_info(spec: dict): +def test_openapi_top_level_info(openapi_spec: dict): """Test all top level informations stored in OpenAPI specification.""" - assert spec.get("openapi") == "3.1.0" + assert openapi_spec.get("openapi") == "3.1.0" - info = spec.get("info") or {} + info = openapi_spec.get("info") or {} @@ -def test_servers_section_present(spec: dict): +def test_servers_section_present(openapi_spec: dict): """Test the servers section stored in OpenAPI specification.""" - servers = spec.get("servers") + servers = openapi_spec.get("servers") @@ -def test_paths_and_responses_exist( - spec: dict, path: str, method: str, expected_codes: t.Set[str] -): +def test_paths_and_responses_exist( + openapi_spec: dict, path: str, method: str, expected_codes: t.Set[str] +): """Tests all paths defined in OpenAPI specification.""" - paths = spec.get("paths") or {} + paths = openapi_spec.get("paths") or {}Also applies to: 33-47, 49-53, 76-90
33-47: Strengthen top-level assertions and avoid shadowing built-in ‘license’.- assert spec.get("openapi") == "3.1.0" + # Accept any 3.1.x patch version to reduce brittleness + assert (openapi_spec.get("openapi") or "").startswith("3.1."), "Expected OpenAPI 3.1.x" @@ - contact = info.get("contact") or {} - assert contact is not None + contact = info.get("contact") or {} + assert isinstance(contact, dict) and contact, "info.contact must be a non-empty object" @@ - license = info.get("license") or {} - assert license.get("name") == "Apache 2.0" - assert "apache.org/licenses" in (license.get("url") or "") + license_info = info.get("license") or {} + assert license_info.get("name") == "Apache 2.0" + assert "apache.org/licenses" in (license_info.get("url") or "")
49-53: Validate server objects contain non-empty ‘url’ fields.servers = spec.get("servers") assert isinstance(servers, list) and servers, "servers must be a non-empty list" + for s in servers: + assert isinstance(s, dict) and s.get("url"), "each server must define a non-empty 'url'"
76-90: Make method lookup case-insensitive; assert responses presence; show all missing codes at once.- op = (paths[path] or {}).get(method) + op = (paths[path] or {}).get(method.lower()) assert isinstance(op, dict), f"Missing method {method.upper()} for path {path}" - responses = op.get("responses") or {} - got_codes = set(responses.keys()) - for code in expected_codes: - assert ( - code in got_codes - ), f"Missing response code {code} for {method.upper()} {path}" + assert "responses" in op and isinstance(op["responses"], dict) and op["responses"], \ + f"Missing or empty responses for {method.upper()} {path}" + responses = op["responses"] + got_codes = set(responses.keys()) + missing = expected_codes - got_codes + assert not missing, f"Missing response codes {sorted(missing)} for {method.upper()} {path}"
55-75: Optional: add ids=… to parametrize for clearer test names in reports.Example:
- ids like "GET /v1/info", "POST /v1/query", etc., matching each tuple.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
tests/integration/test_openapi_json.py(1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Python linter
tests/integration/test_openapi_json.py
[warning] 1-1: Missing module docstring (C0114).
[warning] 17-17: Inconsistent return statements (R1710).
[warning] 33-33: Redefining name 'spec' from outer scope (redefined-outer-name).
[warning] 44-44: Redefining built-in 'license' (redefined-builtin).
[warning] 49-49: Redefining name 'spec' from outer scope (redefined-outer-name).
[warning] 77-77: Redefining name 'spec' from outer scope (redefined-outer-name).
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build-pr
- GitHub Check: e2e_tests
827524d to
3d22371
Compare
Description
Elementary OpenAPI integration tests
Type of change
Implements: LCORE-628
Summary by CodeRabbit